<?
/*

	Archive list
	Sidebar plugin
	
*/	

	// Tell the system we are a sidebar plugin
	function archive_pluginType() { 
		return "sidebar";	
	}
	
	// Tell the system our full name
	function archive_pluginName() {
		return "Puddle archive";
	}
	
	// The description of our services as a plugin
	function archive_pluginDescription() {
		return "Show the archive of puddle entries";
	}
	
	// can we edit settings?
	function archive_hasEdit() {
		return true;
	}
	

	// This is displayed to the user , and should contain all options for setting up the plugin
	//	 presetoptions is an array
	//		either null or contains all the options incase of editing this plugin
	function archive_optionForm($presetoptions) {
		if ($presetoptions) $values=explode("|",$presetoptions);

		$form="";
		$form.="Title for widget<br/>";
		$form.="<input type='text' name='title'";
		if ($presetoptions) $form.="value='".$values[2]."'";
		$form.="/>";
		
		return $form;
	}


	// Assemble the plugin return string based on the $_POST array values
	//	use | between each setting..  result will be htmlified
	function archive_addPlugin() {
		$formline="";
		//$formline.=$_POST['content'];
		return $formline;
	}
	
	
	// Print the result !
	function archive_draw($line) {
		global $blogRoot,$lang;
		
		print "<h2>".$line."</h2>";
		
		// now we fetch the archives
		$handle=opendir($blogRoot."txts/"); 
		
		$year=null;
		
		// process all archive files
		while ($file = readdir($handle)) { 
			if (substr($file,0,1)!="." && substr($file,0,1)!="_" && (filesize($blogRoot."txts/".$file)!="0")) {
				$newyear=substr($file,0,4);
				$archive[$file]=$newyear;
			}
		}
		
		krsort($archive);

		print "<div class='sidebarcontent'>";

		foreach ($archive as $key=>$value) {
				if ($value!=$year) {
					if ($year) print "</ul>";
				
					$year=$value;
					
					print "<h2>".$year."</h2>";
					print "<ul>";
				}
				
				$file=$blogRoot."txts/".$key;
				$load = @file($file);
				print "<li><a href='".$blogRoot."../?archive=".str_replace(".txt","",$key)."'>".$lang["months"][str_replace("0","",substr($key,5,2))]."  (".count($load).")</a></li>";
		}
	
		print "</div>";
		

	}

?>